package com.guet.niit.Login.service;

import com.guet.niit.Login.dao.LoginDao;
import com.guet.niit.Login.dao.LoginDaoImpl;
import com.guet.niit.Login.pojo.Agent;
import com.guet.niit.Login.pojo.User;
import javafx.scene.control.Alert;

import java.util.List;

public class LoginService {
    private LoginDao loginDao = new LoginDaoImpl();

    /**
     * 检查用户名和密码是否输入正确
     * @return
     */
    public List<User> userCheckLogin() {
        List<User> loginList = loginDao.userCheckLogin();
        return loginList;
    }

    /**
     * 检查代理商名和密码是否输入正确
     * @return
     */
    public List<Agent> agentCheckLogin() {
        List<Agent> loginList = loginDao.agentCheckLogin();
        return loginList;
    }

    /**
     * 注册新的普通用户
     * @param user
     */
    public void userRegister(User user) {
        int count = loginDao.userRegister(user);
        if (count>0){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("注册成功！");
            alert.showAndWait();
        }
    }

    /**
     * 注册新的代理商
     * @param agent
     */
    public void agentRegister(Agent agent) {
        int count = loginDao.agentRegister(agent);
        if (count>0){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("注册成功！");
            alert.showAndWait();
        }
    }
}
